package com.spring.cloud.client.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import lombok.extern.slf4j.Slf4j;

@RestController
@Slf4j
public class ComputeController {

	@Autowired
	private DiscoveryClient client;
	/*@Autowired
	LoadBalancerClient loadBalancerClient;*/

	
	
	@GetMapping("/add")
	public Integer name(@RequestParam Integer a, @RequestParam Integer b) {
		ServiceInstance instance = client.getLocalServiceInstance();
		//ServiceInstance instance = loadBalancerClient.choose("client-name");
		Integer r = a + b;
		log.info("/add, host:" + instance.getHost() + 
				", service_id:" +
				instance.getServiceId() + 
				", result:" + r);
		return r;
	}
}
